<?php

class Application_Model_DbTable_VehicleClient extends Zend_Db_Table_Abstract
{

    protected $_name = 'vehiculo_cliente';

     public function getVehicleClient($placa)
    {
        try{
            $row = $this->fetchRow(
                $this->select()
                ->where('placa= ?', $placa)
            );
            if ($row) {
                 return $row->toArray();
            }
            else{
                return $row;
            }       
        }catch(Zend_Exception $e){
            throw $e;
        }
    }
    
    public function addVehicleClient($placa, $cliente)
    {
        $data = array(
            'placa' => $placa,
            'cliente' => $cliente,
        );
        $this->insert($data);
    }
    
    public function updateVehicleClient($placa,$cliente)
    {
        $data = array(
             'placa' => $placa,
            'cliente' => $cliente,
        );
        $this->update($data, 'placa = ' . (int)$placa);
    }
    
    public function deleteVehicleClient($placa)
    {
        $this->delete('placa = ' . (int)$placa);
    }

    public function findUserVehicle($ced){
        $row = $this->fetchall($this->select()
            ->where('cliente = ?', $ced));
        if (!$row) {
            throw new Exception("Could not find row");
        }
        return $row->toArray();
    }

    public function deleteVehicles($ced){
        $this->delete('cliente = '.$ced);        
    }

}